package com.project.nhantvt.SessionBean;

import java.util.ArrayList;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.project.entity.Enquiry;

/**
 * Session Bean implementation class EnquiryBean
 */
@Stateless
@LocalBean
public class EnquiryBean implements EnquiryBeanRemote {

    /**
     * Default constructor. 
     */
	
	@PersistenceContext
	EntityManager em;
	
    public EnquiryBean() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public ArrayList<Enquiry> GetAllEnquiry() {
		Query query = em.createQuery("From Enquiry");
		ArrayList<Enquiry> lst = (ArrayList<Enquiry>) query.getResultList();
		
		return lst;
	}

	@Override
	public boolean remove(int enquiryID) {
		Enquiry e = em.find(Enquiry.class, enquiryID);
		em.remove(e);
		
		return true;
	}

	@Override
	public boolean createEnquiry(Enquiry enq) {
		em.persist(enq);
		return true;
	}

}
